<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
  <script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>挂号-->${message}</legend>
</fieldset>
<form  id="guahaoform" method="post" class="layui-form layui-form-pane" action="${pageContext.request.contextPath}/registered/addregistered">
  <div class="layui-form-item">
    <div class="layui-inline">
    <label class="layui-form-label">患者姓名</label>
    <div class="layui-input-inline">
      <input type="text" name="personname" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
    <div class="layui-inline">
      <label class="layui-form-label">出生日期</label>
      <div class="layui-input-block">
        <input type="text" name="birthday" id="date1" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">年龄</label>
      <div class="layui-input-inline">
        <input type="text" name="age" autocomplete="off" class="layui-input">
      </div>
    </div>
     <div class="layui-inline">
      <label class="layui-form-label">家庭住址</label>
      <div class="layui-input-inline">
        <input type="text" name="address" autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label">身份证</label>
    <div class="layui-input-block">
      <input type="text" name="idcard" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  

   <div class="layui-form-item">
   <div class="layui-inline">
    <label class="layui-form-label">病历本</label>
    <div class="layui-input-block">
      <input type="radio" name="flag" lay-filter="jiedian" value="1" title="是" >
      <input type="radio" name="flag" lay-filter="jiedian" value="2" title="否" checked="checked">
    </div>
  </div>
    
    <label class="layui-form-label">挂号科室</label>
    <div class="layui-input-inline">
      <select name="dept.deptid" id="keshi" lay-filter="one_cate">
      </select>
    </div>
     <label class="layui-form-label">看诊医生</label>
    <div class="layui-input-inline">
      <select name="doctor.doctorid" id="doctor" >
      </select>
    </div>
    <label class="layui-form-label" >挂号级别</label>
    <div class="layui-input-inline">
      <select name="reglevel.levelid" id="level" lay-filter="two_cate">
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">挂号日期</label>
      <div class="layui-input-block">
        <input type="text" name="regdate" id="date" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
    <label class="layui-form-label">应收金额</label>
    <div class="layui-input-inline">
      <input type="text" name="money" id="money" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
    </div>
    </div> 
  <div class="layui-form-item">
    <button class="layui-btn" lay-submit="" lay-filter="demo2" id="guahao" >挂号</button> 
  </div>
  
</form>     
 <table class="layui-hide" id="person"></table>
 <script src="${pageContext.request.contextPath}/static/js/table_reg.js"></script>
<!-- layui.use  按需加载模板  类似于js的入口函数-->
<script>
layui.use(['form','layedit','laydate','jquery'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,$ = layui.jquery; 
  //日期
  laydate.render({
    elem: '#date1'
    
  });
  laydate.render({
	elem: '#date'
	  });
  //查询科室和挂号等级
  $.ajax({
	  type:"post",
	  url:"${pageContext.request.contextPath}/home/onloadReg",
	  success:function(data){
		 var depts=data.data.depts;
		 var reglevels=data.data.reglevels;
		 $("#keshi").empty();
		 $('#level').empty();
		 //new Option(标签体内容,value)
		 $("#keshi").append(new Option("请选择参数",""));
		 $('#level').append(new Option("请选择级别",""));
		 $.each(depts,function(index,item){
			 $("#keshi").append(new Option(item.deptname,item.deptid))
		 })
		 $.each(reglevels,function(index,item){
			 $("#level").append(new Option(item.levelname,item.levelid))
		 })
		 //渲染下拉列表
		 form.render('select')
	  }
  })
  //select(one_cate) layui的事件 医生下拉列表联动
  form.on('select(one_cate)',function(data){
	  //获取下拉列表正在选着的option的value值
	  var deptid=data.value
	 	$.ajax({
	 		type:"post",
	 		url:"${pageContext.request.contextPath}/doctor/getDoctorByDeptid",
	 		data:"deptid="+deptid,
	 		success:function(data){
	 			//将数据拼接到看诊医生的下拉列表中
	 			 console.log(data.data) 
	 			 var doctors=data.data
	 			 $("#doctor").empty();
	 			$.each(doctors,function(index,item){
	 				//拼接数据
	 				$("#doctor").append(new Option(item.doctorname,item.doctorid))
	 			})
	 			//渲染下拉列表
	 			form.render('select');
	 		}
	 	})
    })
	 //获取应收金额
	 form.on('select(two_cate)',function(data){
		 var levelid=data.value;
		 $.ajax({
			 type:"post",
			 url:"${pageContext.request.contextPath}/reglevel/queryLevelById",
			 data:"levelid="+levelid,
			 success:function(result){
				 var m=result.data.charge
				 /* alert(result.data.charge) */
				 $("#money").val(m);
			 }
		 })
	 })
	 
	 form.on('radio(jiedian)',function(data){
		/*  alert(data.value) */
		var level=data.value
		var v=$("#money").val();
		 if(level == "1"){
			 //如果点击是 先判断应收金额是否为空，如果不为空+1
			 if(v != ""){
				 $("#money").val(parseInt(v)+1);
			 }
		 }else{
			 $("#money").val(parseInt(v)-1);
		 }
	 })
 
  //表单提交
  $("#guahao").click(function(){
	  $("#guahaoform").submit();
  });
});
</script>
</body>
</html>